// ActivityWatcher.cpp: implementation of the CActivityWatcher class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "SFDL3.h"
#include "ActivityWatcher.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif


CActivityWatcher::CActivityWatcher()
{
	::GetCursorPos(&m_Last);

	int i=0;
	int j;
	for (j=LETTER_S;j<=LETTER_E;j++)
	{
		m_TestCodes[i++]=j;
	}
	for (j=DIGIT_S;j<=DIGIT_E;j++)
	{
		m_TestCodes[i++]=j;
	}
	for (j=NPAD_S;j<=NPAD_E;j++)
	{
		m_TestCodes[i++]=j;
	}
	for (j=COMMON_S;j<=COMMON_E;j++)
	{
		m_TestCodes[i++]=j;
	}
}

bool CActivityWatcher::CheckMouseMove()
{
	POINT pnt;
	::GetCursorPos(&pnt);

	bool ret=(m_Last!=pnt);

	m_Last=pnt;
	return ret;
}

bool CActivityWatcher::CheckKeyBoard()
{
	for (int i=0;i<sizeof(m_TestCodes)/sizeof(int);i++)
	{
		if (GetAsyncKeyState(m_TestCodes[i]))
		{
			return true;
		}
	}
	return false;
}

bool CActivityWatcher::CheckMouseClick()
{
	for (int iCode=0x01;iCode<0x4;iCode++)
	{
		if (GetAsyncKeyState(iCode))
		{
			return true;
		}
	}
	return false;
}

bool CActivityWatcher::Update()
{
	if(CheckMouseMove())
		return true;
	if (CheckMouseClick())
	{
		return true;
	}
	return CheckKeyBoard();
}

CActivityWatcher& CActivityWatcher::Instance()
{
	static CActivityWatcher watcher;
	return watcher;
}

